home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Range / Range.C < prev    next >
C/C++ Source or Header  |  1992-05-15  |  3KB  |  83 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. //
  13.  
  14. #include <cool/Range.h>
  15.  
  16. // CoolRange<Type,lbound,hbound> -- Constructor with initial value
  17. // Input:         Reference to value
  18. // Output:        None
  19.  
  20. template <class Type, Type lbound, Type hbound>
  21. CoolRange<Type,lbound,hbound>::CoolRange<Type,lbound,hbound> (const Type& value) {
  22.   this->set(value);
  23. }
  24.  
  25.  
  26. // CoolRange<Type,lbound,hbound> -- Constructor with reference to another range
  27. //                object
  28. // Input:         Reference to CoolRange<Type,lbound,hbound> object
  29. // Output:        None
  30.  
  31. template <class Type, Type lbound, Type hbound>
  32. CoolRange<Type,lbound,hbound>::CoolRange<Type,lbound,hbound>
  33.     (const CoolRange<Type,lbound,hbound>& r) {
  34.   this->data = r.data;                // Copy data value
  35. }
  36.  
  37.  
  38.  
  39.  
  40. // operator= -- Overload the assignment operator to copy the value of one
  41. //              CoolRange<Type,lbound,hbound> object to another
  42. // Input:       Reference to object
  43. // Output:      Reference to updated object
  44.  
  45. template <class Type, Type lbound, Type hbound>
  46. CoolRange<Type,lbound,hbound>& CoolRange<Type,lbound,hbound>::operator= (const CoolRange<Type,lbound,hbound>& r) {
  47.   this->data = r.data;                // Copy data value
  48.   return *this;                    // Return reference to object
  49. }
  50.  
  51.  
  52. // value_string -- method to convert value to string
  53. // Input:         None
  54. // Output:        string for value
  55.  
  56. template <class Type, Type lbound, Type hbound>
  57. char* CoolRange<Type,lbound,hbound>::value_string() const {
  58.   ostream str_stream(MSG_MAX, msg_buffer);
  59.   str_stream << data;                // "print" value into buffer
  60.   return strdup(msg_buffer);
  61. }
  62.  
  63.  
  64. template <class Type, Type lbound, Type hbound>
  65. void CoolRange<Type,lbound,hbound>::report_set_error () const {
  66.   if (this->data < this->low_bound)
  67.     this->set_low_error (#Type, #lbound, #hbound,
  68.              this->value_string());
  69.   else if (this->data > this->high_bound)
  70.     this->set_upper_error (#Type, #lbound, #hbound,
  71.                this->value_string());
  72. }
  73.   
  74. template <class Type, Type lbound, Type hbound>
  75. void CoolRange<Type,lbound,hbound>::do_compare () const {
  76.   if ((*this->compare_s)(this->data, this->low_bound) < 0)      // Lower bounds
  77.     this->set_low_error (#Type, #lbound, #hbound,
  78.              this->value_string());
  79.   else if ((*this->compare_s)(this->data, this->high_bound) > 0)// Upper bounds
  80.     this->set_upper_error (#Type, #lbound, #hbound,
  81.                this->value_string());
  82. }
  83.